/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.manchini.stereocv.telas;

import br.com.manchini.stereocv.bd.ControleBD;
import br.com.manchini.stereocv.classes.amostradisparidade.AmostraDisparidade;
import br.com.manchini.stereocv.classes.parametrosdisparidade.ParamentrosDisparidade;
import br.com.manchini.stereocv.utils.CamResolucao;
import br.com.manchini.stereocv.utils.FileUtils;
import br.com.manchini.stereocv.utils.ImgUtils;
import com.googlecode.javacv.CanvasFrame;
import com.googlecode.javacv.FrameGrabber;
import com.googlecode.javacv.OpenCVFrameGrabber;
import com.googlecode.javacv.cpp.opencv_calib3d;
import com.googlecode.javacv.cpp.opencv_core;
import static com.googlecode.javacv.cpp.opencv_core.*;
import com.googlecode.javacv.cpp.opencv_core.IplImage;
import static com.googlecode.javacv.cpp.opencv_imgproc.*;
import static com.googlecode.javacv.cpp.opencv_calib3d.*;
import static com.googlecode.javacv.cpp.opencv_highgui.*;
import static com.googlecode.javacv.cpp.opencv_photo.*;
import java.awt.AWTException;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Robot;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultComboBoxModel;


import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author manchini
 */
public class AjusteDisparidade extends javax.swing.JDialog {

    private Thread thread;
    private static OpenCVFrameGrabber grabberEsq;
    private static CanvasFrame canvasFrameEsq;
    private static IplImage imgEsq;
    //
    private static OpenCVFrameGrabber grabberDir;
    private static CanvasFrame canvasFrameDir;
    private static IplImage imgDir;
    private static CanvasFrame canvasFrame;
    CvMat Q = new CvMat(cvLoad("Q.xml", null, null, null));
    CvMat M1 = new CvMat(cvLoad("M1.xml", null, null, null));
    CvMat M2 = new CvMat(cvLoad("M2.xml", null, null, null));
    CvMat D1 = new CvMat(cvLoad("D1.xml", null, null, null));
    CvMat D2 = new CvMat(cvLoad("D2.xml", null, null, null));
    CvMat R1 = new CvMat(cvLoad("R1.xml", null, null, null));
    CvMat R2 = new CvMat(cvLoad("R2.xml", null, null, null));
    CvMat mx1 = new CvMat(cvLoad("mx1.xml", null, null, null));
    CvMat my1 = new CvMat(cvLoad("my1.xml", null, null, null));
    CvMat mx2 = new CvMat(cvLoad("mx2.xml", null, null, null));
    CvMat my2 = new CvMat(cvLoad("my2.xml", null, null, null));
    
    private int segundo;
    private int fps;

    /**
     * Creates new form ImagemSequencia
     */
    public AjusteDisparidade(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();

        jComboBox_resolucao.setModel(new DefaultComboBoxModel(CamResolucao.values()));
        jComboBox_resolucao.setSelectedIndex(1);
    }

    private void captura() {
        try {
            Integer camEsq = (Integer) jSpinner_esq.getValue();
            Integer camDir = (Integer) jSpinner_dir.getValue();

            CamResolucao camResolucao = (CamResolucao) jComboBox_resolucao.getSelectedItem();
            if (camEsq != -1) {

                grabberEsq = new OpenCVFrameGrabber(camEsq);
                grabberEsq.setImageWidth(camResolucao.getW());
                grabberEsq.setImageHeight(camResolucao.getH());
                grabberEsq.start();

                imgEsq = grabberEsq.grab();
                canvasFrameEsq = new CanvasFrame("Cam Esq");
                jPanel_camesq.add(canvasFrameEsq.getCanvas());
                canvasFrameEsq.setCanvasSize(imgEsq.width(), imgEsq.height());

                grabberEsq.setFrameRate(grabberEsq.getFrameRate());

                IplImage imgEsqOriginal = grabberEsq.grab();

                if (jCheckBox_Rotaciona.isSelected()) {
                    ImgUtils.rotacionaImagem(imgEsqOriginal, imgEsq);
                } else {
                    imgEsq = imgEsqOriginal;
                }


                cvRemap(imgEsq, imgEsq, mx1, my1, CV_INTER_LINEAR, CvScalar.ZERO);

                canvasFrameEsq.showImage(imgEsq);


            }

            ////


            ///
            if (camDir != -1) {
                grabberDir = new OpenCVFrameGrabber(camDir);
                grabberDir.setImageWidth(camResolucao.getW());
                grabberDir.setImageHeight(camResolucao.getH());
                grabberDir.start();

                imgDir = grabberDir.grab();
                canvasFrameDir = new CanvasFrame("Cam Dir");
                jPanel_camdir.add(canvasFrameDir.getCanvas());
                canvasFrameDir.setCanvasSize(imgDir.width(), imgDir.height());

                grabberDir.setFrameRate(grabberDir.getFrameRate());
                IplImage imgDirOriginal = grabberDir.grab();

                if (jCheckBox_Rotaciona.isSelected()) {
                    ImgUtils.rotacionaImagem(imgDirOriginal, imgDir);
                } else {
                    imgDir = imgDirOriginal;
                }

                cvRemap(imgDir, imgDir, mx2, my2, CV_INTER_LINEAR, CvScalar.ZERO);
//                canvasFrameDir.showImage(imgDir);

            }
            canvasFrame = new CanvasFrame("Disparidade");

          
            calcularDisparidade(true);
          


        } catch (FrameGrabber.Exception ex) {
            JOptionPane.showMessageDialog(this, "Erro");
            ex.printStackTrace();
        }
    }

    private void carregaFoto() {
        try {
            Integer aux = (Integer) jSpinner_dir1.getValue();

            imgEsq = cvLoadImage("img/" + aux + "esq.jpg");
            
//            CvMat imgEsqP = CvMat.create(imgEsq.asCvMat().rows(), imgEsq.asCvMat().cols(), imgEsq.asCvMat().channels(),imgEsq.asCvMat().depth());
//            
            cvRemap(imgEsq, imgEsq, mx1, my1, CV_INTER_LINEAR, CvScalar.ZERO);
            
//            imgEsq = imgEsqP.asIplImage();

            canvasFrameEsq = new CanvasFrame("Cam Esq");
            jPanel_camesq.add(canvasFrameEsq.getCanvas());
            canvasFrameEsq.setCanvasSize(imgEsq.width(), imgEsq.height());
            canvasFrameEsq.showImage(imgEsq);

            imgDir = cvLoadImage("img/" + aux + "dir.jpg");

            cvRemap(imgDir, imgDir, mx2, my2, CV_INTER_LINEAR, CvScalar.ZERO);


            canvasFrameDir = new CanvasFrame("dir");
//            jPanel_camdir.add(canvasFrameDir.getCanvas());
            canvasFrameDir.setVisible(true);
            
            canvasFrameDir.getCanvas().addMouseListener(new MouseAdapter() {
                    @Override
                    public void mouseClicked(MouseEvent e) {
                        capturaCor(e.getXOnScreen(), e.getYOnScreen());
                    }
                });

            cvSaveImage("img/left.ppm", imgEsq);
            cvSaveImage("img/right.ppm", imgDir);

            calcularDisparidade(false);



        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "Erro");
            ex.printStackTrace();
        }
    }

    public synchronized void calcularDisparidade(boolean salvar) {
        try {
            opencv_calib3d.StereoBM bm = new opencv_calib3d.StereoBM();
            bm.init(opencv_calib3d.StereoBM.BASIC_PRESET, (Integer) jSpinner_numberOfDisparities.getValue(), (Integer) jSpinner_SADWindowSize.getValue());
            CvSize img_size = imgDir.cvSize();


            /**
             * BMState->preFilterSize = 41; BMState->preFilterCap = 31;
             * BMState->SADWindowSize = 41; BMState->minDisparity = -64;
             * BMState->numberOfDisparities = 128; BMState->textureThreshold =
             * 10; BMState->uniquenessRatio = 15;
             */
            bm.state().preFilterCap((Integer) jSpinner_preFilterCap.getValue());
            bm.state().SADWindowSize((Integer) jSpinner_SADWindowSize.getValue());
            bm.state().preFilterSize((Integer) jSpinner_preFilterSize.getValue());
            bm.state().minDisparity((Integer) jSpinner_minDisparity.getValue());
            bm.state().numberOfDisparities((Integer) jSpinner_numberOfDisparities.getValue());
            bm.state().textureThreshold((Integer) jSpinner_textureThreshold.getValue());
            bm.state().uniquenessRatio((Integer) jSpinner_uniquenessRatio.getValue());
            bm.state().speckleWindowSize((Integer) jSpinner_speckleWindowSize.getValue());
            bm.state().speckleRange((Integer) jSpinner_speckleRange.getValue());
//            bm.state().disp12MaxDiff((Integer) jSpinner_disp12MaxDiff.getValue());


            CvMat disparidade = cvCreateMat(imgDir.height(), imgDir.width(), CV_16SC1);

            CvMat imgEsqP = opencv_core.CvMat.create(imgDir.height(), imgDir.width(), CV_8UC1);
            CvMat imgDirP = opencv_core.CvMat.create(imgDir.height(), imgDir.width(), CV_8UC1);

            cvCvtColor(imgEsq, imgEsqP, CV_BGR2GRAY);
            cvCvtColor(imgDir, imgDirP, CV_BGR2GRAY);
            fastNlMeansDenoising(imgEsqP, imgEsqP, 7, 21, 3);
            fastNlMeansDenoising(imgDirP, imgDirP, 7, 21, 3);


//            if (salvar) {
//                cvSaveImage("img/left.ppm", imgEsqP);
//                cvSaveImage("img/right.ppm", imgDirP);
//            }

            cvFindStereoCorrespondenceBM(imgEsqP, imgDirP, disparidade, bm.state());

            cvNormalize(disparidade, disparidade, 0, 256, CV_MINMAX, null);

            //        jPanel_camdir.add(canvasFrame.getCanvas());

//             Thread.sleep(1000);

            canvasFrameDir.showImage(disparidade.asIplImage());



        } catch (Exception ex) {
            Logger.getLogger(AjusteDisparidade.class.getName()).log(Level.SEVERE, null, ex);
        }
        //calculo de FPS
        int atual = Calendar.getInstance().get(Calendar.SECOND);
        
        if(atual == segundo){
            fps++;
        }else{
            jLabel_FPS.setText(String.valueOf(fps));
            segundo = atual;
            fps = 0;
        }




    }

    private void liveAction() {
        Integer camEsq = (Integer) jSpinner_esq.getValue();
        Integer camDir = (Integer) jSpinner_dir.getValue();

        
        CamResolucao camResolucao = (CamResolucao) jComboBox_resolucao.getSelectedItem();
        if (camEsq != -1) {
            try {
                grabberEsq = new OpenCVFrameGrabber(camEsq);
                grabberEsq.setImageWidth(camResolucao.getW());
                grabberEsq.setImageHeight(camResolucao.getH());
                grabberEsq.start();

                imgEsq = grabberEsq.grab();
                canvasFrameEsq = new CanvasFrame("Cam Esq");
                jPanel_camesq.add(canvasFrameEsq.getCanvas());
                canvasFrameEsq.setCanvasSize(imgEsq.width(), imgEsq.height());

                grabberEsq.setFrameRate(grabberEsq.getFrameRate());
                
                   canvasFrameEsq.getCanvas().addMouseListener(new MouseAdapter() {
                    @Override
                    public void mouseClicked(MouseEvent e) {
                        try {
                            int x = e.getX();
                            int y = e.getY();
                            //Imagens Disparidade
                            Graphics graphics = canvasFrameDir.getCanvas().getBufferStrategy().getDrawGraphics();
                            Robot r = new Robot();
                            Color pixelColor = r.getPixelColor(jPanel_camdir.getX()+x, jPanel_camdir.getY()+y);
                            double estimarDistancia = ImgUtils.estimarDistancia(pixelColor, new Integer(jTextField_id.getText()));
                            
                            r.mouseMove(jPanel_camdir.getX()+x, jPanel_camdir.getY()+y);
                            
                            JOptionPane.showMessageDialog(AjusteDisparidade.this, "Distancia Estimada = "+estimarDistancia+" cm \n"+pixelColor.toString());
                            
                        } catch (AWTException ex) {
                            Logger.getLogger(AjusteDisparidade.class.getName()).log(Level.SEVERE, null, ex);
                        }
                        
                    }
                });






//                canvasFrameEsq.showImage(imgEsq);
            } ////
            catch (FrameGrabber.Exception ex) {
                Logger.getLogger(AjusteDisparidade.class.getName()).log(Level.SEVERE, null, ex);
            }


        }


        ////


        ///
        if (camDir != -1) {
            try {
                grabberDir = new OpenCVFrameGrabber(camDir);
                grabberDir.setImageWidth(camResolucao.getW());
                grabberDir.setImageHeight(camResolucao.getH());
                grabberDir.start();

                imgDir = grabberDir.grab();
                canvasFrameDir = new CanvasFrame("Cam Dir");
                jPanel_camdir.add(canvasFrameDir.getCanvas());
                canvasFrameDir.setCanvasSize(imgDir.width(), imgDir.height());
                canvasFrameDir.getCanvas().addMouseListener(new MouseAdapter() {
                    @Override
                    public void mouseClicked(MouseEvent e) {
                        capturaCor(e.getXOnScreen(), e.getYOnScreen());
                    }
                });

                grabberDir.setFrameRate(grabberDir.getFrameRate());

            } catch (FrameGrabber.Exception ex) {
                Logger.getLogger(AjusteDisparidade.class.getName()).log(Level.SEVERE, null, ex);
            }

        }


        new Thread(new Runnable() {
            @Override
            public void run() {

                while (true) {
                    try {
                        IplImage imgEsqOriginal = grabberEsq.grab();

                        if (jCheckBox_Rotaciona.isSelected()) {
                            ImgUtils.rotacionaImagem(imgEsqOriginal, imgEsq);
                        } else {
                            imgEsq = imgEsqOriginal;
                        }



                        IplImage imgDirOriginal = grabberDir.grab();

                        if (jCheckBox_Rotaciona.isSelected()) {
                            ImgUtils.rotacionaImagem(imgDirOriginal, imgDir);
                        } else {
                            imgDir = imgDirOriginal;
                        }

                        cvRemap(imgDir, imgDir, mx2, my2, CV_INTER_LINEAR, CvScalar.ZERO);
                        cvRemap(imgEsq, imgEsq, mx1, my1, CV_INTER_LINEAR, CvScalar.ZERO);

                        canvasFrameEsq.showImage(imgEsq);
//                        canvasFrameDir.showImage(imgDir);

                        calcularDisparidade(false);


                    } catch (FrameGrabber.Exception ex) {
                        Logger.getLogger(AjusteDisparidade.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }

            }
        }).start();

        canvasFrame = new CanvasFrame("Disparidade");
    }

    private void carregaParametro() {
        ControleBD controleBD = new ControleBD();
        try {

            Integer id = new Integer(jTextField_id.getText());
            ParamentrosDisparidade paramentrosDisparidade = new ParamentrosDisparidade();
            paramentrosDisparidade.setId(id);
            ParamentrosDisparidade existe = null;
            if ((existe = (ParamentrosDisparidade) controleBD.existe(paramentrosDisparidade)) != null) {
                jTextField_nome.setText(existe.getNome());
                jSpinner_preFilterCap.setValue(existe.getPreFilterCap());
                jSpinner_SADWindowSize.setValue(existe.getSadWindowSize());
                jSpinner_minDisparity.setValue(existe.getMinDisparity());
                jSpinner_numberOfDisparities.setValue(existe.getNumberOfDisparities());
                jSpinner_textureThreshold.setValue(existe.getTextureThreshold());
                jSpinner_uniquenessRatio.setValue(existe.getUniquenessRatio());

                jSpinner_preFilterSize.setValue(existe.getPreFilterSize());
                jSpinner_speckleWindowSize.setValue(existe.getSpeckleWindowSize());
                jSpinner_speckleRange.setValue(existe.getSpeckleRange());
                jSpinner_disp12MaxDiff.setValue(existe.getDisp12MaxDiff());
                atualizaTabela(existe);

            } else {

                ArrayList<ParamentrosDisparidade> lista = controleBD.listar(ParamentrosDisparidade.class);
                StringBuilder st = new StringBuilder(200);
                for (int i = 0; i < lista.size(); i++) {
                    ParamentrosDisparidade aux = lista.get(i);
                    st.append(aux.getId()).append(" - ").append(aux.getNome()).append("\n");
                }
                JOptionPane.showMessageDialog(this, "ID não Existe Tente algum Item Abaixo:\n" + st.toString());
            }

        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            controleBD.close();
        }
    }

    private void salvarParametros() {
        ControleBD controleBD = new ControleBD();
        try {

            Integer id = null;
            ParamentrosDisparidade paramentrosDisparidade = null;
            if (!jTextField_id.getText().isEmpty()) {
                paramentrosDisparidade = new ParamentrosDisparidade();
                id = new Integer(jTextField_id.getText());
                paramentrosDisparidade.setId(id);
                paramentrosDisparidade = (ParamentrosDisparidade) controleBD.existe(paramentrosDisparidade);
            } else {
            }
            if (paramentrosDisparidade == null) {
                paramentrosDisparidade = new ParamentrosDisparidade();
                paramentrosDisparidade.setId(controleBD.listar(ParamentrosDisparidade.class).size());
            }

            paramentrosDisparidade.setNome(jTextField_nome.getText());
            paramentrosDisparidade.setPreFilterCap((Integer) jSpinner_preFilterCap.getValue());
            paramentrosDisparidade.setSadWindowSize((Integer) jSpinner_SADWindowSize.getValue());
            paramentrosDisparidade.setMinDisparity((Integer) jSpinner_minDisparity.getValue());
            paramentrosDisparidade.setNumberOfDisparities((Integer) jSpinner_numberOfDisparities.getValue());
            paramentrosDisparidade.setTextureThreshold((Integer) jSpinner_textureThreshold.getValue());
            paramentrosDisparidade.setUniquenessRatio((Integer) jSpinner_uniquenessRatio.getValue());

            paramentrosDisparidade.setPreFilterSize((Integer) jSpinner_preFilterSize.getValue());
            paramentrosDisparidade.setSpeckleWindowSize((Integer) jSpinner_speckleWindowSize.getValue());
            paramentrosDisparidade.setSpeckleRange((Integer) jSpinner_speckleRange.getValue());
            paramentrosDisparidade.setDisp12MaxDiff((Integer) jSpinner_disp12MaxDiff.getValue());

            controleBD.store(paramentrosDisparidade);

            jTextField_id.setText(paramentrosDisparidade.getId().toString());

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            controleBD.close();
        }
    }

    private void atualizaTabela(ParamentrosDisparidade paramentrosDisparidade) {
        DefaultTableModel tm = (DefaultTableModel) jTable1.getModel();
        tm.setRowCount(0);

        ArrayList<AmostraDisparidade> amostras = paramentrosDisparidade.getAmostras();
        for (int i = 0; i < amostras.size(); i++) {
            AmostraDisparidade amostraDisparidade = amostras.get(i);
            Object[] row = new Object[2];
            row[0] = amostraDisparidade.getDistancia();
            row[1] = amostraDisparidade.getColor().toString();
            tm.addRow(row);
        }


    }

    private void capturaCor(int x, int y) {
        if (jTextField_id.getText().isEmpty()) {
            JOptionPane.showMessageDialog(this, "ID do Parametros deve ser Informado");
            return;
        }
        ControleBD controleBD = new ControleBD();
        try {

            Integer id = new Integer(jTextField_id.getText());
            ParamentrosDisparidade paramentrosDisparidade = new ParamentrosDisparidade();
            paramentrosDisparidade.setId(id);
            ParamentrosDisparidade existe = null;
            if ((existe = (ParamentrosDisparidade) controleBD.existe(paramentrosDisparidade)) != null) {
                paramentrosDisparidade = existe;

                AmostraDisparidade amostra = new AmostraDisparidade();
                amostra.setDistancia((Double) jSpinner_distancia.getValue());
                Robot robot = new Robot();
                Color c = robot.getPixelColor(x, y);
                amostra.setColor(c);

                paramentrosDisparidade.setAmostras((ArrayList<AmostraDisparidade>) (paramentrosDisparidade.getAmostras() == null ? new ArrayList<>() : new ArrayList<>(paramentrosDisparidade.getAmostras())));
                paramentrosDisparidade.getAmostras().add(amostra);

                controleBD.store(paramentrosDisparidade);
                atualizaTabela(paramentrosDisparidade);

            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            controleBD.close();
        }


    }
    
    private void removerAmostragem() {
        if (jTextField_id.getText().isEmpty()) {
            JOptionPane.showMessageDialog(this, "ID do Parametros deve ser Informado");
            return;
        }
        ControleBD controleBD = new ControleBD();
        try {

            Integer id = new Integer(jTextField_id.getText());
            ParamentrosDisparidade paramentrosDisparidade = new ParamentrosDisparidade();
            paramentrosDisparidade.setId(id);
            ParamentrosDisparidade existe = null;
            if ((existe = (ParamentrosDisparidade) controleBD.existe(paramentrosDisparidade)) != null) {
                paramentrosDisparidade = existe;
                int selectedRow = jTable1.getSelectedRow();
                paramentrosDisparidade.getAmostras().remove(selectedRow);

                paramentrosDisparidade.setAmostras((ArrayList<AmostraDisparidade>) (paramentrosDisparidade.getAmostras() == null ? new ArrayList<>() : new ArrayList<>(paramentrosDisparidade.getAmostras())));
                controleBD.store(paramentrosDisparidade);
                atualizaTabela(paramentrosDisparidade);



            }
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            controleBD.close();
        }


    }

    private void exportarMedicao() {
        if (jTextField_id.getText().isEmpty()) {
            JOptionPane.showMessageDialog(this, "ID do Parametros deve ser Informado");
            return;
        }
        ControleBD controleBD = new ControleBD();
        try {

            Integer id = new Integer(jTextField_id.getText());
            ParamentrosDisparidade paramentrosDisparidade = new ParamentrosDisparidade();
            paramentrosDisparidade.setId(id);
            ParamentrosDisparidade existe = null;
            if ((existe = (ParamentrosDisparidade) controleBD.existe(paramentrosDisparidade)) != null) {
                paramentrosDisparidade = existe;

                StringBuilder st = new StringBuilder(100);
                st.append("Id=").append(paramentrosDisparidade.getId()).append("\n");

                st.append("Nome").append("=").append(existe.getNome()).append("\n");
                st.append("PreFilterCap").append("=").append(existe.getPreFilterCap()).append("\n");
                st.append("SadWindowSize").append("=").append(existe.getSadWindowSize()).append("\n");
                st.append("MinDisparity").append("=").append(existe.getMinDisparity()).append("\n");
                st.append("NumberOfDisparities").append("=").append(existe.getNumberOfDisparities()).append("\n");
                st.append("TextureThreshold").append("=").append(existe.getTextureThreshold()).append("\n");
                st.append("UniquenessRatio").append("=").append(existe.getUniquenessRatio()).append("\n");

                st.append("PreFilterSize").append("=").append(existe.getPreFilterSize()).append("\n");
                st.append("SpeckleWindowSize").append("=").append(existe.getSpeckleWindowSize()).append("\n");
                st.append("SpeckleRange").append("=").append(existe.getSpeckleRange()).append("\n");
                st.append("Disp12MaxDiff").append("=").append(existe.getDisp12MaxDiff()).append("\n");

                st.append("\n\nDistancias\n");
                ArrayList<AmostraDisparidade> amostras = paramentrosDisparidade.getAmostras();

                for (int i = 0; i < amostras.size(); i++) {
                    AmostraDisparidade amostra = amostras.get(i);
                    st.append(amostra.getDistancia()).append("=").append(amostra.getColor().getBlue()).append("\n");

                }




                FileUtils.gravaArquivo(st, "exportacao/" + paramentrosDisparidade.getNome() + ".csv");

            }
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            controleBD.close();
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel7 = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jSpinner_esq = new javax.swing.JSpinner();
        jLabel2 = new javax.swing.JLabel();
        jSpinner_dir = new javax.swing.JSpinner();
        jCheckBox_Rotaciona = new javax.swing.JCheckBox();
        jComboBox_resolucao = new javax.swing.JComboBox();
        jPanel2 = new javax.swing.JPanel();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jSpinner_dir1 = new javax.swing.JSpinner();
        jPanel8 = new javax.swing.JPanel();
        jPanel_menu = new javax.swing.JPanel();
        jPanel5 = new javax.swing.JPanel();
        jLabel14 = new javax.swing.JLabel();
        jTextField_id = new javax.swing.JTextField();
        jButton_Carrega = new javax.swing.JButton();
        jLabel15 = new javax.swing.JLabel();
        jTextField_nome = new javax.swing.JTextField();
        jButton_Salvar = new javax.swing.JButton();
        jButton_Salvar1 = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jSpinner_preFilterCap = new javax.swing.JSpinner();
        jLabel5 = new javax.swing.JLabel();
        jSpinner_SADWindowSize = new javax.swing.JSpinner();
        jLabel6 = new javax.swing.JLabel();
        jSpinner_minDisparity = new javax.swing.JSpinner();
        jLabel7 = new javax.swing.JLabel();
        jSpinner_numberOfDisparities = new javax.swing.JSpinner();
        jLabel8 = new javax.swing.JLabel();
        jSpinner_textureThreshold = new javax.swing.JSpinner();
        jLabel9 = new javax.swing.JLabel();
        jSpinner_uniquenessRatio = new javax.swing.JSpinner();
        jPanel4 = new javax.swing.JPanel();
        jLabel13 = new javax.swing.JLabel();
        jSpinner_preFilterSize = new javax.swing.JSpinner();
        jLabel10 = new javax.swing.JLabel();
        jSpinner_speckleWindowSize = new javax.swing.JSpinner();
        jLabel11 = new javax.swing.JLabel();
        jSpinner_speckleRange = new javax.swing.JSpinner();
        jLabel12 = new javax.swing.JLabel();
        jSpinner_disp12MaxDiff = new javax.swing.JSpinner();
        jPanel9 = new javax.swing.JPanel();
        jPanel6 = new javax.swing.JPanel();
        jLabel16 = new javax.swing.JLabel();
        jSpinner_distancia = new javax.swing.JSpinner();
        jLabel17 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jPanel_camesq = new javax.swing.JPanel();
        jPanel_camdir = new javax.swing.JPanel();
        jPanel10 = new javax.swing.JPanel();
        jLabel_FPS = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                formMouseClicked(evt);
            }
        });

        jPanel7.setLayout(new javax.swing.BoxLayout(jPanel7, javax.swing.BoxLayout.Y_AXIS));

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Cameras"));

        jLabel1.setText("Esquerda");
        jPanel1.add(jLabel1);

        jSpinner_esq.setModel(new javax.swing.SpinnerNumberModel(1, -1, 5, 1));
        jPanel1.add(jSpinner_esq);

        jLabel2.setText("Direita");
        jPanel1.add(jLabel2);

        jSpinner_dir.setModel(new javax.swing.SpinnerNumberModel(2, -1, 5, 1));
        jPanel1.add(jSpinner_dir);

        jCheckBox_Rotaciona.setText("Rotaciona Imagem");
        jCheckBox_Rotaciona.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox_RotacionaActionPerformed(evt);
            }
        });
        jPanel1.add(jCheckBox_Rotaciona);

        jPanel1.add(jComboBox_resolucao);

        jPanel7.add(jPanel1);

        jButton3.setText("Live Action");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });
        jPanel2.add(jButton3);

        jButton4.setText("Carrega Fotos");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });
        jPanel2.add(jButton4);

        jSpinner_dir1.setModel(new javax.swing.SpinnerNumberModel(1, 0, 9999, 1));
        jPanel2.add(jSpinner_dir1);

        jPanel7.add(jPanel2);

        jPanel8.setLayout(new java.awt.BorderLayout());
        jPanel7.add(jPanel8);

        jTabbedPane1.addTab("Inicializar Imagens", jPanel7);

        jPanel_menu.setLayout(new javax.swing.BoxLayout(jPanel_menu, javax.swing.BoxLayout.Y_AXIS));

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Parametros de Disparidade"));
        jPanel5.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));

        jLabel14.setText("ID:");
        jPanel5.add(jLabel14);

        jTextField_id.setPreferredSize(new java.awt.Dimension(50, 27));
        jPanel5.add(jTextField_id);

        jButton_Carrega.setText("Carregar");
        jButton_Carrega.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_CarregaActionPerformed(evt);
            }
        });
        jPanel5.add(jButton_Carrega);

        jLabel15.setText("Nome:");
        jPanel5.add(jLabel15);

        jTextField_nome.setPreferredSize(new java.awt.Dimension(200, 27));
        jPanel5.add(jTextField_nome);

        jButton_Salvar.setText("Salvar");
        jButton_Salvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_SalvarActionPerformed(evt);
            }
        });
        jPanel5.add(jButton_Salvar);

        jButton_Salvar1.setText("Limpar");
        jButton_Salvar1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_Salvar1ActionPerformed(evt);
            }
        });
        jPanel5.add(jButton_Salvar1);

        jPanel_menu.add(jPanel5);

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Parametros de Disparidade"));
        jPanel3.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));

        jLabel4.setText("preFilterCap");
        jPanel3.add(jLabel4);

        jSpinner_preFilterCap.setModel(new javax.swing.SpinnerNumberModel(30, 1, 63, 1));
        jSpinner_preFilterCap.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jSpinner_uniquenessRatioStateChanged(evt);
            }
        });
        jSpinner_preFilterCap.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                jSpinner_uniquenessRatioPropertyChange(evt);
            }
        });
        jPanel3.add(jSpinner_preFilterCap);

        jLabel5.setText("SADWindowSize");
        jPanel3.add(jLabel5);

        jSpinner_SADWindowSize.setModel(new javax.swing.SpinnerNumberModel(29, 5, 255, 1));
        jSpinner_SADWindowSize.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jSpinner_uniquenessRatioStateChanged(evt);
            }
        });
        jSpinner_SADWindowSize.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                jSpinner_uniquenessRatioPropertyChange(evt);
            }
        });
        jSpinner_SADWindowSize.addVetoableChangeListener(new java.beans.VetoableChangeListener() {
            public void vetoableChange(java.beans.PropertyChangeEvent evt)throws java.beans.PropertyVetoException {
                jSpinner_uniquenessRatioVetoableChange(evt);
            }
        });
        jPanel3.add(jSpinner_SADWindowSize);

        jLabel6.setText("minDisparity");
        jPanel3.add(jLabel6);

        jSpinner_minDisparity.setModel(new javax.swing.SpinnerNumberModel(0, -100, 100, 1));
        jSpinner_minDisparity.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jSpinner_uniquenessRatioStateChanged(evt);
            }
        });
        jSpinner_minDisparity.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                jSpinner_uniquenessRatioPropertyChange(evt);
            }
        });
        jSpinner_minDisparity.addVetoableChangeListener(new java.beans.VetoableChangeListener() {
            public void vetoableChange(java.beans.PropertyChangeEvent evt)throws java.beans.PropertyVetoException {
                jSpinner_uniquenessRatioVetoableChange(evt);
            }
        });
        jPanel3.add(jSpinner_minDisparity);

        jLabel7.setText("numberOfDisparities");
        jPanel3.add(jLabel7);

        jSpinner_numberOfDisparities.setModel(new javax.swing.SpinnerNumberModel(48, 16, 256, 16));
        jSpinner_numberOfDisparities.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jSpinner_uniquenessRatioStateChanged(evt);
            }
        });
        jSpinner_numberOfDisparities.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                jSpinner_uniquenessRatioPropertyChange(evt);
            }
        });
        jSpinner_numberOfDisparities.addVetoableChangeListener(new java.beans.VetoableChangeListener() {
            public void vetoableChange(java.beans.PropertyChangeEvent evt)throws java.beans.PropertyVetoException {
                jSpinner_uniquenessRatioVetoableChange(evt);
            }
        });
        jPanel3.add(jSpinner_numberOfDisparities);

        jLabel8.setText("textureThreshold");
        jPanel3.add(jLabel8);

        jSpinner_textureThreshold.setModel(new javax.swing.SpinnerNumberModel(10, 0, 32000, 1));
        jSpinner_textureThreshold.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jSpinner_uniquenessRatioStateChanged(evt);
            }
        });
        jSpinner_textureThreshold.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                jSpinner_uniquenessRatioPropertyChange(evt);
            }
        });
        jSpinner_textureThreshold.addVetoableChangeListener(new java.beans.VetoableChangeListener() {
            public void vetoableChange(java.beans.PropertyChangeEvent evt)throws java.beans.PropertyVetoException {
                jSpinner_uniquenessRatioVetoableChange(evt);
            }
        });
        jPanel3.add(jSpinner_textureThreshold);

        jLabel9.setText("uniquenessRatio");
        jPanel3.add(jLabel9);

        jSpinner_uniquenessRatio.setModel(new javax.swing.SpinnerNumberModel(9, 0, 255, 1));
        jSpinner_uniquenessRatio.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jSpinner_uniquenessRatioStateChanged(evt);
            }
        });
        jSpinner_uniquenessRatio.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                jSpinner_uniquenessRatioPropertyChange(evt);
            }
        });
        jSpinner_uniquenessRatio.addVetoableChangeListener(new java.beans.VetoableChangeListener() {
            public void vetoableChange(java.beans.PropertyChangeEvent evt)throws java.beans.PropertyVetoException {
                jSpinner_uniquenessRatioVetoableChange(evt);
            }
        });
        jPanel3.add(jSpinner_uniquenessRatio);

        jPanel_menu.add(jPanel3);

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Parametros de Disparidade"));
        jPanel4.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));

        jLabel13.setText("preFilterSize");
        jPanel4.add(jLabel13);

        jSpinner_preFilterSize.setModel(new javax.swing.SpinnerNumberModel(5, 5, 255, 1));
        jSpinner_preFilterSize.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jSpinner_preFilterSizejSpinner_uniquenessRatioStateChanged(evt);
            }
        });
        jSpinner_preFilterSize.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                jSpinner_preFilterSizejSpinner_uniquenessRatioPropertyChange(evt);
            }
        });
        jSpinner_preFilterSize.addVetoableChangeListener(new java.beans.VetoableChangeListener() {
            public void vetoableChange(java.beans.PropertyChangeEvent evt)throws java.beans.PropertyVetoException {
                jSpinner_preFilterSizejSpinner_uniquenessRatioVetoableChange(evt);
            }
        });
        jPanel4.add(jSpinner_preFilterSize);

        jLabel10.setText("speckleWindowSize");
        jPanel4.add(jLabel10);

        jSpinner_speckleWindowSize.setModel(new javax.swing.SpinnerNumberModel(41, 0, 100, 1));
        jSpinner_speckleWindowSize.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jSpinner_uniquenessRatioStateChanged(evt);
            }
        });
        jSpinner_speckleWindowSize.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                jSpinner_uniquenessRatioPropertyChange(evt);
            }
        });
        jSpinner_speckleWindowSize.addVetoableChangeListener(new java.beans.VetoableChangeListener() {
            public void vetoableChange(java.beans.PropertyChangeEvent evt)throws java.beans.PropertyVetoException {
                jSpinner_uniquenessRatioVetoableChange(evt);
            }
        });
        jPanel4.add(jSpinner_speckleWindowSize);

        jLabel11.setText("speckleRange");
        jPanel4.add(jLabel11);

        jSpinner_speckleRange.setModel(new javax.swing.SpinnerNumberModel(55, 0, 100, 1));
        jSpinner_speckleRange.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jSpinner_uniquenessRatioStateChanged(evt);
            }
        });
        jSpinner_speckleRange.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                jSpinner_uniquenessRatioPropertyChange(evt);
            }
        });
        jSpinner_speckleRange.addVetoableChangeListener(new java.beans.VetoableChangeListener() {
            public void vetoableChange(java.beans.PropertyChangeEvent evt)throws java.beans.PropertyVetoException {
                jSpinner_uniquenessRatioVetoableChange(evt);
            }
        });
        jPanel4.add(jSpinner_speckleRange);

        jLabel12.setText("disp12MaxDiff");
        jPanel4.add(jLabel12);

        jSpinner_disp12MaxDiff.setModel(new javax.swing.SpinnerNumberModel(1, 0, 200, 1));
        jSpinner_disp12MaxDiff.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jSpinner_uniquenessRatioStateChanged(evt);
            }
        });
        jSpinner_disp12MaxDiff.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                jSpinner_uniquenessRatioPropertyChange(evt);
            }
        });
        jSpinner_disp12MaxDiff.addVetoableChangeListener(new java.beans.VetoableChangeListener() {
            public void vetoableChange(java.beans.PropertyChangeEvent evt)throws java.beans.PropertyVetoException {
                jSpinner_uniquenessRatioVetoableChange(evt);
            }
        });
        jPanel4.add(jSpinner_disp12MaxDiff);

        jPanel_menu.add(jPanel4);

        jTabbedPane1.addTab("Parametros", jPanel_menu);

        jPanel9.setLayout(new javax.swing.BoxLayout(jPanel9, javax.swing.BoxLayout.Y_AXIS));

        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder("Amostragem de Distancia"));
        jPanel6.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));

        jLabel16.setText("Distancia em cm:");
        jPanel6.add(jLabel16);

        jSpinner_distancia.setModel(new javax.swing.SpinnerNumberModel(1.0d, 1.0d, 9999.0d, 1.0d));
        jSpinner_distancia.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jSpinner_distanciajSpinner_uniquenessRatioStateChanged(evt);
            }
        });
        jSpinner_distancia.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                jSpinner_distanciajSpinner_uniquenessRatioPropertyChange(evt);
            }
        });
        jPanel6.add(jSpinner_distancia);

        jLabel17.setText("**Clicando sobre a disparidade ira salvar a Distancia");
        jPanel6.add(jLabel17);

        jButton1.setText("Remover Amostra");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jPanel6.add(jButton1);

        jButton5.setText("Exportar");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });
        jPanel6.add(jButton5);

        jPanel9.add(jPanel6);

        jScrollPane1.setPreferredSize(new java.awt.Dimension(452, 200));

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Distancia", "Cor"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(jTable1);

        jPanel9.add(jScrollPane1);

        jTabbedPane1.addTab("Amostragens", jPanel9);

        getContentPane().add(jTabbedPane1, java.awt.BorderLayout.NORTH);

        jPanel_camesq.setPreferredSize(new java.awt.Dimension(600, 300));
        jPanel_camesq.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jPanel_camesqMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanel_camesqLayout = new javax.swing.GroupLayout(jPanel_camesq);
        jPanel_camesq.setLayout(jPanel_camesqLayout);
        jPanel_camesqLayout.setHorizontalGroup(
            jPanel_camesqLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 600, Short.MAX_VALUE)
        );
        jPanel_camesqLayout.setVerticalGroup(
            jPanel_camesqLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 318, Short.MAX_VALUE)
        );

        getContentPane().add(jPanel_camesq, java.awt.BorderLayout.WEST);

        jPanel_camdir.setPreferredSize(new java.awt.Dimension(600, 300));
        jPanel_camdir.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jPanel_camdirMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanel_camdirLayout = new javax.swing.GroupLayout(jPanel_camdir);
        jPanel_camdir.setLayout(jPanel_camdirLayout);
        jPanel_camdirLayout.setHorizontalGroup(
            jPanel_camdirLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 600, Short.MAX_VALUE)
        );
        jPanel_camdirLayout.setVerticalGroup(
            jPanel_camdirLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 318, Short.MAX_VALUE)
        );

        getContentPane().add(jPanel_camdir, java.awt.BorderLayout.EAST);

        jPanel10.setPreferredSize(new java.awt.Dimension(1287, 20));
        jPanel10.add(jLabel_FPS);

        getContentPane().add(jPanel10, java.awt.BorderLayout.PAGE_END);

        setSize(new java.awt.Dimension(1297, 669));
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void jCheckBox_RotacionaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox_RotacionaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jCheckBox_RotacionaActionPerformed

    private void jSpinner_uniquenessRatioVetoableChange(java.beans.PropertyChangeEvent evt)throws java.beans.PropertyVetoException {//GEN-FIRST:event_jSpinner_uniquenessRatioVetoableChange
    }//GEN-LAST:event_jSpinner_uniquenessRatioVetoableChange

    private void jSpinner_uniquenessRatioPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_jSpinner_uniquenessRatioPropertyChange
    }//GEN-LAST:event_jSpinner_uniquenessRatioPropertyChange

    private void jSpinner_uniquenessRatioStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jSpinner_uniquenessRatioStateChanged
        calcularDisparidade(false);
    }//GEN-LAST:event_jSpinner_uniquenessRatioStateChanged

    private void jSpinner_preFilterSizejSpinner_uniquenessRatioStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jSpinner_preFilterSizejSpinner_uniquenessRatioStateChanged
        // TODO add your handling code here:
    }//GEN-LAST:event_jSpinner_preFilterSizejSpinner_uniquenessRatioStateChanged

    private void jSpinner_preFilterSizejSpinner_uniquenessRatioPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_jSpinner_preFilterSizejSpinner_uniquenessRatioPropertyChange
        // TODO add your handling code here:
    }//GEN-LAST:event_jSpinner_preFilterSizejSpinner_uniquenessRatioPropertyChange

    private void jSpinner_preFilterSizejSpinner_uniquenessRatioVetoableChange(java.beans.PropertyChangeEvent evt)throws java.beans.PropertyVetoException {//GEN-FIRST:event_jSpinner_preFilterSizejSpinner_uniquenessRatioVetoableChange
        // TODO add your handling code here:
    }//GEN-LAST:event_jSpinner_preFilterSizejSpinner_uniquenessRatioVetoableChange

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        liveAction();
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton_SalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_SalvarActionPerformed
        salvarParametros();
    }//GEN-LAST:event_jButton_SalvarActionPerformed

    private void jButton_CarregaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_CarregaActionPerformed
        carregaParametro();
    }//GEN-LAST:event_jButton_CarregaActionPerformed

    private void jButton_Salvar1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_Salvar1ActionPerformed
        jTextField_id.setText("");
        jTextField_nome.setText("");
    }//GEN-LAST:event_jButton_Salvar1ActionPerformed

    private void jSpinner_distanciajSpinner_uniquenessRatioStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jSpinner_distanciajSpinner_uniquenessRatioStateChanged
        // TODO add your handling code here:
    }//GEN-LAST:event_jSpinner_distanciajSpinner_uniquenessRatioStateChanged

    private void jSpinner_distanciajSpinner_uniquenessRatioPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_jSpinner_distanciajSpinner_uniquenessRatioPropertyChange
        // TODO add your handling code here:
    }//GEN-LAST:event_jSpinner_distanciajSpinner_uniquenessRatioPropertyChange

    private void jPanel_camesqMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jPanel_camesqMouseClicked
    }//GEN-LAST:event_jPanel_camesqMouseClicked

    private void formMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_formMouseClicked

    private void jPanel_camdirMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jPanel_camdirMouseClicked

        capturaCor(evt.getXOnScreen(), evt.getYOnScreen());
    }//GEN-LAST:event_jPanel_camdirMouseClicked

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        carregaFoto();
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
      removerAmostragem();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
    exportarMedicao();
    }//GEN-LAST:event_jButton5ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(AjusteDisparidade.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(AjusteDisparidade.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(AjusteDisparidade.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(AjusteDisparidade.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                AjusteDisparidade dialog = new AjusteDisparidade(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton_Carrega;
    private javax.swing.JButton jButton_Salvar;
    private javax.swing.JButton jButton_Salvar1;
    private javax.swing.JCheckBox jCheckBox_Rotaciona;
    private javax.swing.JComboBox jComboBox_resolucao;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JLabel jLabel_FPS;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel10;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JPanel jPanel_camdir;
    private javax.swing.JPanel jPanel_camesq;
    private javax.swing.JPanel jPanel_menu;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSpinner jSpinner_SADWindowSize;
    private javax.swing.JSpinner jSpinner_dir;
    private javax.swing.JSpinner jSpinner_dir1;
    private javax.swing.JSpinner jSpinner_disp12MaxDiff;
    private javax.swing.JSpinner jSpinner_distancia;
    private javax.swing.JSpinner jSpinner_esq;
    private javax.swing.JSpinner jSpinner_minDisparity;
    private javax.swing.JSpinner jSpinner_numberOfDisparities;
    private javax.swing.JSpinner jSpinner_preFilterCap;
    private javax.swing.JSpinner jSpinner_preFilterSize;
    private javax.swing.JSpinner jSpinner_speckleRange;
    private javax.swing.JSpinner jSpinner_speckleWindowSize;
    private javax.swing.JSpinner jSpinner_textureThreshold;
    private javax.swing.JSpinner jSpinner_uniquenessRatio;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField jTextField_id;
    private javax.swing.JTextField jTextField_nome;
    // End of variables declaration//GEN-END:variables
}
